package com.xizi.leetcode周赛;

import java.util.Arrays;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-8-29上午 11:28
 */
public class _5854_学生分数的最小差值 {


    // 1 4 7 9 len=4 k=2
    public int minimumDifference(int[] nums, int k) {
        int res = Integer.MAX_VALUE;
        if (k <= 1) {
            return 0;
        }
        Arrays.sort(nums);
        for (int i = 0; i <= nums.length - k; i++) {
            int temp = nums[i + k - 1] - nums[i];
            res = Math.min(res, temp);
        }
        return res;
    }
}
